package main

import (
	"bytes"
	"fmt"
	"net/http"
)

type ResponseWriterWrapper struct {
	w          http.ResponseWriter
	body       bytes.Buffer
	statusCode int
}

func (i *ResponseWriterWrapper) Write(buf []byte) (int, error) {
	i.body.Write(buf)
	return i.w.Write(buf)
}

func (i *ResponseWriterWrapper) WriteHeader(statusCode int) {
	i.statusCode = statusCode
	i.w.WriteHeader(statusCode)
}

func (i *ResponseWriterWrapper) Header() http.Header {
	return i.w.Header()
}

func (i *ResponseWriterWrapper) String() {
	var buf bytes.Buffer

	buf.WriteString("Response:")

	buf.WriteString("Headers:")
	for k, v := range i.w.Header() {
		buf.WriteString(fmt.Sprintf("%s: %v", k, v))
	}

	buf.WriteString(fmt.Sprintf("Status Code: %d", i.statusCode))

	buf.WriteString("Body")
	buf.WriteString(i.body.String())
}

func (i *ResponseWriterWrapper) Content() string {
	return i.body.String()
}
